<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>编辑图片</title>
<%@include file="/common/meta.jsp"%>
<%@include file="/common/validator.jsp"%>
<script type="text/javascript">
jQuery.noConflict();
</script>
<%@include file="/common/ec.jsp"%>
<%@include file="/common/dwr.jsp"%>
<script type="text/javascript"	src="${ctx}/dwr/interface/CatalogDwrAction.js"></script>
<script type="text/javascript"	src="${ctx}/scripts/fckeditor/fckeditor.js"></script>
<script type="text/javascript" src="${ctx}/scripts/TabPanel/tabpanel.js"></script>
<link rel="stylesheet" type="text/css"	href="${ctx}/scripts/TabPanel/css/style.css" />
<script type="text/javascript" src="${ctx}/dwr/interface/ArticleAction.js"></script>
</head>
<script type="text/javascript">
function onDisplay(){
    document.getElementById("wordNumber").style.display = "block";
}

function onHide(){
	 document.getElementById("wordNumber").style.display = "none";
}
/** set parentId */
function setCatalog(){
	CatalogDwrAction.getCatalog("catalog","1",function(catalog){
		DWRUtil.removeAllOptions("catalogId");
		DWRUtil.addOptions($("catalogId"), catalog,
    		function getValue(catalog) {
    			return catalog.id;
    		},
    		function getText(catalog) {
    			return catalog.text;
    		});
    	//设置默认栏目，用于修改时
		DWRUtil.setValue("catalogId", $('model.catalog.id').value);
		} 
	);
}
function addHttp(obj){
	if (obj.value == "" || obj.value == null) {
		obj.value = "http://";
	} 
}


//增加文件输入框 
function addFileInput(){
  var oFileInputTable = document.getElementById("fileUpload");
  var fileIndex = oFileInputTable.childNodes.length + 1;
  var oTR  = document.createElement("TR");
  var oTD1 = document.createElement("TD");
  var oTD2 = document.createElement("TD");
  
  
  oTR.setAttribute("id","file_"+fileIndex);    
  oTD1.setAttribute("style","text-align:right;");
  oTD2.setAttribute("style","text-align:left;");
  oTD2.innerHTML = '<input type="file" name="attachments" cssClass="FileText" style="width:300px;"/>&nbsp;&nbsp;&nbsp;&nbsp;描述：<textarea name="descns" cols="30" rows="2"></textarea>&nbsp;<A href="javascript:deleteFileInput('+fileIndex+');"><img src="${ctx}/images/icons/delete.gif"></A>';
  
      
  oTR.appendChild(oTD1);
  oTR.appendChild(oTD2);
  
  oFileInputTable.appendChild(oTR);
}

//删除文件输入框
function deleteFileInput(childId) {
  var oTR = document.getElementById("file_"+childId);
	var oFileInputTable = document.getElementById("fileUpload");;
	oFileInputTable.removeChild(oTR);
}
</script>
<script type="text/javascript">
function deleteAttachment(attachmentId) {
	if (confirm("确定要删除吗？")) {
  	deleteDiv(attachmentId);
      ArticleAction.removeAttachments(attachmentId,
	function (msg) {
	  if (msg == 'success') {
	    alert('删除成功！');
	  } else if(msg == 'error') {
	    alert('文章下存在附件不能删除。');
	  }
	}
);
}
}
	function deleteDiv(attachmentId) {
		document.getElementById('attachments'+attachmentId).style.display='none'; 
		document.getElementById('attachments'+attachmentId).innerHTML=""; 
		document.getElementById('attachments'+attachmentId).removeNode(); 
	}
</script>
<body onload="setCatalog();">
<s:form namespace="/admin/article" id="saveImage" action="saveArticle"
	theme="simple" method="POST" enctype="multipart/form-data">
	<input type="hidden" name="type" value="${type}"></input>
	<div class="x-panel">
	<div class="x-panel-header">图片管理</div>
	<div class="x-toolbar">&nbsp;</div>
	<table width="100%" border="0" cellpadding="4" cellspacing="1">
		<tr>
			<td><%@ include file="/common/messages.jsp"%></td>
		</tr>
	</table>
	<s:hidden name="model.id" /> <s:hidden name="model.version" /> 
	<s:hidden name="model.createTime" /> <s:hidden name="model.updateTime" />
	 <s:hidden name="model.inputer.id" />
	<fieldset style="margin: 10px;"><legend>编辑图片信息</legend>
	<table width="98%" border="0" align="center">
		<tr>
			<td>

			<table width="100%" align="center" cellpadding="4" cellspacing="1">
				<tr>
					<td width="90">
					<div align="right"><span class="font_b">所属栏目：</span></div>
					</td>
					<td width="" colspan="2">
					<table id="coloum">
						<tr id="clmTr">
							<td><select id="catalogId" name="catalogId"/>
								<s:hidden name="model.catalog.id" id="model.catalog.id" /></td>
							<td align="right" width="140"><span class="prompting">*请选择该图片所属的栏目</span>
							</td>
						</tr>
					</table>
					</td>
				</tr>
				<tr>
					<td width="90" align="right">简短标题：</td>
					<td><s:textfield cssStyle="background-image : url('../../images/icons/TxtRule.jpg');"
						name="model.shortTitle" theme="simple" size="70"
						id="model.shortTitle" maxlength="170" cssClass="required" />&nbsp;<font
						color="red">*</font><span class="prompting">简短标题为页面显示标题 </span>
					</td>
				</tr>
				<tr>
					<td width="90" align="right">完整标题：</td>
					<td>
						<s:textfield name="model.title" theme="simple" size="70"
						id="model.title" maxlength="250" cssClass="required" />&nbsp;<font
						color="red">*</font>
					</td>
				</tr>
				<tr>
					<td width="90" align="right">副&nbsp;标&nbsp;题：</td>
					<td>
					<s:textfield name="model.subtitle" theme="simple"
						size="70" id="subtitle" maxlength="170" cssClass="required" />&nbsp;<font
						color="red">*</font>
					</td>
				</tr>
			</table>
			</td>
		</tr>
		<tr>
			<td>
			<table align="center" width="100%" cellpadding="4" cellspacing="1">
				<tr>
					<td width="90">
					<div align="right"><span class="font_b">转向链接：</span></div>
					</td>
					<td><s:textfield name="model.linkUrl" onfocus="addHttp(this)"
						theme="simple" size="30" id="linkUrl" maxlength="255" />
					<span class="prompting"> * 请填写有效的网址(如:http://www.systop.com.cn)</span>	
					</td>
					<td width="280"></td>
				</tr>
				<tr>
					<td width="90">
					<div align="right"><span class="font_b">图片作者：</span></div>
					</td>
					<td><s:textfield name="model.author" theme="simple" size="30"
						id="author" maxlength="100" /></td>
					<td width="18%"></td>
				</tr>
				<tr>
					<td width="90">
					<div align="right"><span class="font_b">图片简介：</span></div>
					</td>
					<td><s:textarea name="model.summary" id="summary" cols="60"
						rows="2"></s:textarea></td>
					<td width="18%"></td>
				</tr>
				<tr>
					<td width="90">
					<div align="right"><span class="font_b">图片属性：</span></div>
					</td>
					<td><input type="checkbox" name="model.onTop" id="onTop"
						value="1" ${model.onTop== 1?"checked":""}/>固顶文章 <input
						type="checkbox" name="model.isElite" id="isElite" value="1"
						${model.isElite== 1?"checked":""} />推荐文章</td>
					<td><span class="STYLE1"></span></td>
				</tr>
			</table>
			</td>
		</tr>
		<tr>
			<td>
			<table align="center" width="100%">
				<tr>
					<td width="90" align="right" style="padding: 10 5 2 5;"><strong>图片附件</strong>
					</td>
					<td style="padding: 10 5 2 5;"><a href="#"
						onclick="javascript:addFileInput();"> <img
						src="${ctx}/images/icons/file_add.gif">增加图片&nbsp; </a></td>
				</tr>
				<tbody id="fileUpload"></tbody>
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td align="right" valign="top" width="90"
						style="border-top: 1px solid black; padding: 5 5 2 5;"><strong>已有图片附件</strong>
					</td>
					<td style="border-top: 1px solid black; padding: 5 5 2 5;"><c:forEach
						var="att" items="${model.attachmentses}">
						<div id="attachments${att.id }">
						<table width="90%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td align="center" valign="middle" scope="col"><a
									href="${ctx}${att.path}" target="_blank"><img
									src="${ctx}${att.pathOther}" /></a></td>
								<td rowspan="2" scope="col"><Strong>描述： </Strong><br>
								<br>
								${att.descn}&nbsp;<br>
								</td>
								<td rowspan="2" scope="col"><a href="#" title="删除"
									onclick="javascript:deleteAttachment(${att.id });"><img
									src="${ctx}/images/icons/delete.gif" /></a></td>
							</tr>
							<tr>
								<td align="center" valign="middle" scope="row"><font
									size="2">${att.name}</font></td>
							</tr>
						</table>
						</div>
					</c:forEach>&nbsp;</td>
				</tr>
			</table>
			</td>
		</tr>
	</table>
	</fieldset>
	<table width="98%" border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td align="center"><s:if test="model.id == null">
				<s:submit value="添加" cssClass="button" />
			</s:if> <s:else>
				<s:submit value="修改" cssClass="button" />
			</s:else> <s:reset value="清空" cssClass="button" onclick="clearFCK();" /></td>
		</tr>
	</table>
	</div>
</s:form>
<script type="text/javascript">
function clearFCK(){
	var editor = FCKeditorAPI.GetInstance("model.content");
	editor.EditorDocument.body.innerHTML="";
}
jQuery(document).ready(function() {
	jQuery("#saveImage").validate();
	});
</script>
</body>
</html>
